Resource leaks are created when an application fails to release one or more resources. Resource leaks consume memory and unnecessarily prevent others from using resources that are limited in availability. For example, a UNIX server may only allow a limited number of sessions, so a session resource that never gets released consumes a resource that may be needed by others. Resource leaks can be problematic in Java because an object associated with the resource may no longer be accessible so that even if a leak is detected, it is often not possible to stop the leak. For example, an application may instantiate an object that is associated with a resource. When the application is finished using the resource, if the application fails to release the resource, a garbage collection process will eventually remove the object. However, in some cases the garbage collection process may not be aware of the resource—e.g., if the resource is a non-Java resource and the garbage collection process and object using the resource are associated with the Java Virtual Machine—and therefore does not release the resource. Even if the resource leak is detected, the resource can no longer be released because the only object referencing the resource and/or having a method for releasing the resource has been removed by the garbage collection process. Thus, an improved method of handling resource leaks is needed.